<template>
  <div class="two-function-area">
    <div class="one-function-title-area">
      <div class="function-area-title-piece"></div>
      <div class="function-area-title">拼团商品配置</div>
    </div>
    <el-divider></el-divider>
    <div class="config-desc">
      <div>拼团形式、价格模式配置</div>
      <p>此拼团配置为相同价格，不同阶梯福利拼团配置，最多可设置5级拼团阶梯。若您需要配置不同价格，可在阶梯福利内容中增加“到店付X元”或“到店退X元”等描述内容。</p>
    </div>
    <div class="welfare-title">
      <div class="title">拼团福利标题</div>
      <div>
        <el-input size="small" v-model="pintuan_goods_config.welfare_title.title"
                  placeholder="请输入拼团福利标题，最多15字" maxlength="15" show-word-limit></el-input>
      </div>
    </div>
    <div class="welfare-config">
      <div class="config-title">拼团商品配置</div>
      <div class="config-content">
        <div class="price-config">
          <div>拼团价</div>
          <div>|</div>
          <div><input v-model="pintuan_goods_config.pintuan_price" type="number" min="0"/></div>
        </div>
        <div class="number-config">
          <div>商品数量</div>
          <div>|</div>
          <div>
            <input v-if="pintuan_goods_config.is_inventory" :disabled="true" class="number-input" v-model="pintuan_goods_config.inventory_number" type="number" min="0"/>
            <input v-if="!pintuan_goods_config.is_inventory" class="number-input" v-model="pintuan_goods_config.inventory_number" type="number" min="0"/>
          </div>
        </div>
        <div class="inventory-config">
          <el-checkbox v-model="pintuan_goods_config.is_inventory">不配置库存</el-checkbox>
        </div>
      </div>
    </div>
    <div class="goods-list">
      <template v-for="(item, index) in pintuan_goods_config.interval_goods_list">
        <div class="goods-card">
          <div class="first-row">
            <div class="goods-card-sort">阶梯 {{ index + 1 }}</div>
            <div class="goods-card-button">
              <el-button v-if="pintuan_goods_config.interval_goods_list.length > 1" type="text" class="button-style" @click="removeGoods(index)">
                <i class="el-icon-error"></i>
              </el-button>
            </div>
          </div>
          <div class="goods-row">
            <div class="goods-one-row">
              <div>成团人数</div>
              <div>|</div>
              <div><input v-model="item.constitute_number" type="number" min="0"/></div>
            </div>
            <div class="goods-two-row">
              <div>福利名称</div>
              <div>|</div>
              <div><input v-model="item.welfare_name" maxlength="24"/></div>
            </div>
          </div>
        </div>
      </template>
    </div>
    <div>
      <div class="add-goods-button">
        <el-button class="goods-button" icon="el-icon-plus" @click="addGoods">添加阶梯福利</el-button>
      </div>
      <div class="pintuan-custom">
        <div class="pintuan-custom-title">高级自定义</div>
        <div class="pintuan-custom-desc">开团列表、区分老客户等</div>
        <div class="pintuan-custom-button">
          <el-button v-if="!pintuan_custom" type="text" @click="pintuan_custom = true">展开
            <i class="el-icon-arrow-down"></i></el-button>
          <el-button v-if="pintuan_custom" type="text" @click="pintuan_custom = false">收起
            <i class="el-icon-arrow-up"></i></el-button>
        </div>
      </div>
      <div v-if="pintuan_custom" class="custom-area">
        <div class="custom-area-style">
          <div>
            <span class="subtitle">开团列表</span>
            <span class="subtitle-desc">显示全部可参与的团，用户自主选择参团</span>
          </div>
          <div class="subtitle-switch">
            <el-switch v-model="pintuan_goods_config.custom.is_show_kaituan_list" active-color="#13ce66" inactive-color="#ff4949"></el-switch>
          </div>
        </div>
        <div class="custom-area-style">
          <div>
            <span class="subtitle">用户自主选择身份</span>
            <span class="subtitle-desc">客户报名时，选择对应身份</span>
          </div>
          <div class="subtitle-switch">
            <el-switch v-model="pintuan_goods_config.custom.is_optional_identity" active-color="#13ce66" inactive-color="#ff4949"></el-switch>
          </div>
        </div>
        <div class="custom-area-style">
          <div>
            <span class="subtitle">活动结束后自动满团</span>
            <span class="subtitle-desc">结束后系统虚拟用户凑满成团人数</span>
          </div>
          <div class="subtitle-switch">
            <el-switch v-model="pintuan_goods_config.custom.is_auto_full_group" active-color="#13ce66" inactive-color="#ff4949"></el-switch>
          </div>
        </div>
        <div class="custom-area-style">
          <div>
            <span class="subtitle">拼团商品</span>
            <span class="subtitle-desc">展示活动拼团商品列表</span>
          </div>
          <div class="subtitle-switch">
            <el-switch v-model="pintuan_goods_config.custom.is_show_goods_list" active-color="#13ce66" inactive-color="#ff4949"></el-switch>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "PintuanGoodsConfig",
  props: ['pintuan_goods_config'],
  data() {
    return {
      pintuan_custom: false
    }
  },
  created() {
  },
  methods: {
    removeGoods(index) {
      this.$emit('remove-goods-item',index);
    },
    addGoods() {
      this.$emit('add-goods-item');
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-divider--horizontal {
  margin: 5px;
}

.two-function-area {
  margin-top: 10px;
  padding-left: 10px;
  .one-function-title-area {
    display: flex;
    position: relative;

    .function-area-title-piece {
      width: 5px;
      height: 30px;
      background-color: #2254f5;
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
    }

    .function-area-title {
      width: 100%;
      height: 40px;
      font-size: 18px;
      font-weight: bold;
      color: #2254f5;
      padding-left: 10px;
      align-content: center;
    }
  }
  .config-desc {
    div {
      padding: 20px 0 5px 0;
      font-size: 14px;
      font-weight: bold;
    }
    p {
      font-size: 12px;
      color: rgba(0,0,0,0.5);
    }
  }
  .welfare-title {
    font-size: 14px;
    .title {
      padding: 10px 0 10px 0;
      font-size: 14px;
      font-weight: bold;
    }
  }
  .welfare-config {
    width: 100%;
    .config-title {
      padding: 20px 0 15px 0;
      font-size: 14px;
      font-weight: bold;
    }
    .config-content {
      width: 100%;
      display: flex;
      .price-config {
        width: 130px;
        height: 30px;
        border: 1px dashed #7d7979;
        border-radius: 5px;
        display: flex;
        div:nth-of-type(1) {
          font-size: 12px;
          width: 50px;
          height: 100%;
          align-content: center;
          text-align: center;
        }
        div:nth-of-type(2) {
          width: 10px;
          text-align: center;
          align-content: center;
        }
        div:nth-of-type(3) {
          text-align: right;
          width: 70px;
          height: 100%;
          input {
            width: 100%;
            height: 100%;
            padding-left: 10px;
            border: none;
          }
        }
        input:focus {
          border: 0 solid #2b2f3a;
        }
      }
      .number-config {
        margin-left: 30px;
        width: 130px;
        height: 30px;
        border: 1px dashed #7d7979;
        border-radius: 5px;
        display: flex;
        div:nth-of-type(1) {
          font-size: 12px;
          width: 50px;
          height: 100%;
          align-content: center;
          text-align: center;
        }
        div:nth-of-type(2) {
          width: 10px;
          text-align: center;
          align-content: center;
        }
        div:nth-of-type(3) {
          text-align: right;
          width: 70px;
          height: 100%;
          input {
            width: 100%;
            height: 100%;
            padding-left: 10px;
            border: none;
          }
        }
      }
      .inventory-config {
        padding-left: 50px;
        align-content: center;
      }
    }
  }
  .goods-list {
    margin: 20px 10px 10px 0;
    .goods-card {
      width: 100%;
      height: 120px;
      background-color: #f6f7f9;
      margin-top: 10px;
      border-radius: 5px;
      .first-row {
        display: flex;
        .goods-card-sort {
          width: 60px;
          height: 25px;
          background-color: #ff4d20;
          font-size: 12px;
          color: white;
          border-radius: 5px 0;
          text-align: center;
          align-content: center;
        }
        .goods-card-button {
          width: 410px;
          text-align: right;
          color: #81878e;
          .button-style {
            padding: 0;
            color: #74777b;
          }
        }
      }
      .goods-row {
        padding: 5px 20px 10px 20px;
        .goods-one-row {
          width: 100%;
          height: 30px;
          margin-top: 5px;
          background-color: #ffffff;
          border-radius: 5px;
          display: flex;
          div:nth-of-type(1) {
            font-size: 12px;
            width: 90px;
            height: 100%;
            align-content: center;
            text-align: center;
          }
          div:nth-of-type(2) {
            width: 10px;
            text-align: center;
            align-content: center;
          }
          div:nth-of-type(3) {
            text-align: right;
            width: 200px;
            height: 100%;
            input {
              width: 100%;
              height: 100%;
              padding-left:20px;
              border: none;
            }
          }
        }
        .goods-two-row {
          width: 100%;
          height: 30px;
          margin-top: 5px;
          background-color: #ffffff;
          border-radius: 5px;
          display: flex;
          div:nth-of-type(1) {
            font-size: 12px;
            width: 90px;
            height: 100%;
            align-content: center;
            text-align: center;
          }
          div:nth-of-type(2) {
            width: 10px;
            text-align: center;
            align-content: center;
          }
          div:nth-of-type(3) {
            text-align: right;
            width: 300px;
            height: 100%;
            input {
              width: 100%;
              height: 100%;
              padding-left:20px;
              border: none;
            }
          }
        }
      }
    }
  }
  .add-goods-button {
    width: 100%;
    height: 50px;
    text-align: center;
    align-content: center;
    .goods-button {
      width: 240px;
    }
  }
  .pintuan-custom {
    padding: 20px 0 10px 0;
    display: flex;
    .pintuan-custom-title {
      min-width: 80px;
      font-size: 14px;
      font-weight: bold;
      color: #ff4d20;
      align-content: center;
    }
    .pintuan-custom-desc {
      width: 300px;
      font-size: 12px;
      align-content: center;
      color: rgba(0, 0, 0, 0.5);
    }
    .pintuan-custom-button {
      width: 100px;
      align-content: center;
      text-align: right;
    }
  }
  .custom-area {
    width: 100%;
    height: 230px;
    border-radius: 10px;
    background-color: #f6f7f9;
    padding: 20px;
    > div {
      width: 100%;
      height: 50px;
    }
    .custom-area-style {
      display: grid;
      grid-template-columns: 80% 20%;
      align-content: center;

      .subtitle {
        font-size: 14px;
        align-content: center;
      }

      .subtitle-desc {
        padding-left: 10px;
        font-size: 12px;
        color: rgba(0, 0, 0, 0.5);
        align-content: center;
      }

      .subtitle-switch {
        text-align: right;
        align-content: center;
      }
    }

    .last-custom {
      padding-top: 10px;

      span:nth-of-type(1) {

      }

      span:nth-of-type(2) {
        vertical-align: middle;
        padding-left: 20px;
        width: 50px;
      }

      span:nth-of-type(3) {
        vertical-align: middle;
        padding-left: 90px;
      }
    }
  }
}
</style>
